package com.skit.common.config

import com.google.gson.GsonBuilder
import com.skit.common.http.HttpUtils.okHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

/**
 * @author shuike [Contact me.](mailto:shuike007@gmail.com)
 * @version 1.0
 * @since 2020/5/21
 */
object RetrofitClient {
    var gson = GsonBuilder()
        .setDateFormat("yyyy-MM-dd HH:mm:ss")
        .create()//Gson

    //获取Retrofit
    val retroClient: Retrofit
        get() = Retrofit.Builder()
            .client(okHttpClient)
            .baseUrl(AppConfig.ROOT_URL.also {
                println(it)
            })
            .addConverterFactory(GsonConverterFactory.create()) //Gson
            .build()

    @JvmStatic
    fun <T> getService(tClass: Class<T>): T {
        val retrofit = retroClient
        return retrofit.create(tClass)
    }
}